Skip to content

TyKind in GlobalAllocs #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

TyKind in GlobalAllocs #84

wants to merge 15 commits into from

Conversation

dkcumming
Copy link
Collaborator

@dkcumming dkcumming commented May 21, 2025

GlobalAllocs need to be decoded to their types, this can be done easier by preprocessing the python (maybe in the future in the repo). But for the python to preprocess it will go easier with the Ty available in the JSON.

  • Changed AllocInfo to be a struct that contains the GlobalAlloc information, originally it was a enum that was a duplicate of stable_mir::mir::alloc::GlobalAlloc. The struct helps with the JSON as the field names come through.
  • Changed the functions that get the TyKind from the allocs and provs to work with Ty
  • collect_alloc also takes a Ty as a parameter instead of a TyKind now
  • AllocMap is now collects the Ty also

@dkcumming dkcumming requested a review from ehildenb May 21, 2025 21:28
@dkcumming dkcumming self-assigned this May 21, 2025
Copy link
Member

@jberthold jberthold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! And makes sense to add the type information at this stage.
Two points to consider changing, however:

  1. The PR proposes to store TyKind (which should always be RigidTy BTW) but the extraction generally (and the semantics so far) instead stores and uses the Ty IDs to refer to a type. By storing RigidTy here we have to engage in decoding the RigidTy to something useful.
  2. The "thing that's useful" already exists in the code as TypeInfo, so we would be duplicating the decoder.

I'd suggest we just store the Ty ID with the alloc instead of the RigidTy and use the lookups into the existing types table and existing decoder code. The change would be relatively easy: At the call site for collect_alloc we can pass in the ty and get the resp. TyKind within collect_alloc.

src/printer.rs Outdated
if debug_enabled() {
println!(
"DEBUG: called collect_alloc: {:?}:{:?}:{:?}",
val, pointed_kind, global_alloc
);
}
entry.or_insert(AllocInfo::Memory(alloc.clone())); // TODO: include pointed_kind.clone().unwrap() ?
entry.or_insert((kind.unwrap(), AllocInfo::Memory(alloc.clone()))); // TODO: include pointed_kind.clone().unwrap() ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
entry.or_insert((kind.unwrap(), AllocInfo::Memory(alloc.clone()))); // TODO: include pointed_kind.clone().unwrap() ?
entry.or_insert((kind.unwrap(), AllocInfo::Memory(alloc.clone())));

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree! Amending now!

{
"kind": "ReErased"
},
31,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the problem that fails the golden tests in CI, the IDs stored here are unstable.

Copy link
Member

@ehildenb ehildenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, but you should probably wait to merge this one until you have a branch ready on KMIR that uses this and can confirm it's populating the <globals> cell correctly.

Copy link
Member

@jberthold jberthold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants